cmake_minimum_required(VERSION 3.26 FATAL_ERROR)

project(executable_file_analyzer)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${CMAKE_CURRENT_SOURCE_DIR}/src)

file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp ${CMAKE_CURRENT_SOURCE_DIR}/analyzer.cpp)

if (MSVC)
    add_compile_options(/W4)
else()
    add_compile_options(-Wall -Wextra -Wpedantic -Os -fdata-sections -ffunction-sections)
endif()

#add_custom_target(copy-compile-commands ALL DEPENDS ${CMAKE_CURRENT_LIST_DIR}/compile_commands.json)
#add_custom_command(
#    OUTPUT ${CMAKE_CURRENT_LIST_DIR}/compile_commands.json
#    COMMAND ${CMAKE_COMMAND} -E copy_if_different
#        ${CMAKE_BINARY_DIR}/compile_commands.json
#        ${CMAKE_CURRENT_LIST_DIR}/compile_commands.json
#    DEPENDS
#        # unlike "proper" targets like executables and libraries, 
#        # custom command / target pairs will not set up source
#        # file dependencies, so we need to list file explicitly here
#        generate-compile-commands
#        ${CMAKE_BINARY_DIR}/compile_commands.json
#)

add_executable(executable-file-analyzer analyzer.cpp ${SOURCES})
set_property(TARGET executable-file-analyzer PROPERTY CXX_STANDARD 23)
